package com.hmdp.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedisConfig {
    @Bean
    public RedissonClient redisClient() {
        //配置类
        Config config = new Config();
        config.useSingleServer().setDatabase(0).setAddress("redis://127.0.0.1:7001");
        return Redisson.create(config);
    }
//    @Bean
//    public LettuceClientConfigurationBuilderCustomizer clientConfigurationBuilderCustomizer(){
//        /**
//         * ReadFrom:
//         * MASTER:从主节点读取
//         * MASTER_PREFERRED:优先从master节点读取，master不可用才读取replica
//         * REPLICA:从slave（replica）节点读取
//         * REPLICA_PREFERRED:优先从slave阶段读取，所有的slave都不可用才读取master
//         *
//         * */
//        return clientConfigurationBuilder -> clientConfigurationBuilder.readFrom(ReadFrom.REPLICA_PREFERRED);
//    }
//}
}
